package nl.hva.three2learn.controller
{
	import flash.events.MouseEvent;
	import flash.events.NetStatusEvent;

	import flash.media.Camera;
	import flash.media.Microphone;

	import flash.net.NetStream;

	import flash.geom.Point;

	import mx.controls.Alert;

	import nl.hva.three2learn.events.BlackboardEvent;
	import nl.hva.three2learn.ui.Line;

	public final class TeacherApplicationHandler extends ApplicationHandler
	{
		private var _ns:NetStream;

		public function TeacherApplicationHandler(controller:ChatController)
		{
			super(controller);
		}

		override public function doInit():void
		{
			super.doInit();
			
			controller.view.currentState = "teacher";
		}

		override protected function onConnect():void
		{
			super.onConnect();

			controller.view.blackboard.addEventListener(BlackboardEvent.NEW_LINE, onBlackboardNewLine);
			controller.view.blackboard.addEventListener(BlackboardEvent.CLEAR, onBlackboardClear);

			_ns = new NetStream(nc);
			_ns.attachCamera(Camera.getCamera());
			_ns.attachAudio(Microphone.getMicrophone());
			_ns.publish("teacher");

			controller.attachCamera(Camera.getCamera());
		}
		
		private function onBlackboardNewLine(e:BlackboardEvent):void
		{
			so.setProperty("lines", e.data);
			so.setDirty("lines");
		}
		
		private function onBlackboardClear(e:BlackboardEvent):void
		{
			so.setProperty("lines", [ ]);
			so.setDirty("lines");
		}
	}
}
